sw/qa/core/doc/doc.cxx         |   18 ++----------------
 sw/qa/core/text/text.cxx       |   13 +------------
 sw/qa/inc/swmodeltestbase.hxx  |   12 ++++++++++++
 sw/qa/uibase/dochdl/dochdl.cxx |   13 +------------
 sw/qa/uibase/frmdlg/frmdlg.cxx |   16 +---------------
 sw/qa/uibase/shells/shells.cxx |   20 +++-----------------
 6 files changed, 20 insertions(+), 72 deletions(-)

New commits:
commit 286aeb8385285220105c21ef352f5c437e19ebb5
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Wed Jul 29 21:03:29 2020 +0200
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Thu Jul 30 09:07:03 2020 +0200

    sw: extract createDoc() from various test suites to a single getSwDoc()
    
    Change-Id: I72d769860be8a401416e57111bea91d7a26ea4e7
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/99751
    Tested-by: Jenkins
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/sw/qa/core/doc/doc.cxx b/sw/qa/core/doc/doc.cxx
index 2229f603569c..4c0afbd538cd 100644
--- a/sw/qa/core/doc/doc.cxx
+++ b/sw/qa/core/doc/doc.cxx
@@ -24,26 +24,12 @@ char const DATA_DIRECTORY[] = "/sw/qa/core/doc/data/";
 /// Covers sw/source/core/doc/ fixes.
 class SwCoreDocTest : public SwModelTestBase
 {
-public:
-    SwDoc* createDoc(const char* pName = nullptr);
 };
 
-SwDoc* SwCoreDocTest::createDoc(const char* pName)
-{
-    if (!pName)
-        loadURL("private:factory/swriter", nullptr);
-    else
-        load(DATA_DIRECTORY, pName);
-
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    return pTextDoc->GetDocShell()->GetDoc();
-}
-
 CPPUNIT_TEST_FIXTURE(SwCoreDocTest, testMathInsertAnchorType)
 {
     // Given an empty document.
-    SwDoc* pDoc = createDoc();
+    SwDoc* pDoc = createSwDoc();
 
     // When inserting an a math object.
     SwWrtShell* pShell = pDoc->GetDocShell()->GetWrtShell();
@@ -66,7 +52,7 @@ CPPUNIT_TEST_FIXTURE(SwCoreDocTest, testMathInsertAnchorType)
 CPPUNIT_TEST_FIXTURE(SwCoreDocTest, testTextboxTextRotateAngle)
 {
     // Check the writing direction of the only TextFrame in the document.
-    SwDoc* pDoc = createDoc("textbox-textrotateangle.odt");
+    SwDoc* pDoc = createSwDoc(DATA_DIRECTORY, "textbox-textrotateangle.odt");
     SwFrameFormats& rFrameFormats = *pDoc->GetSpzFrameFormats();
     CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), rFrameFormats.size());
     CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(RES_DRAWFRMFMT), 
rFrameFormats[0]->Which());
diff --git a/sw/qa/core/text/text.cxx b/sw/qa/core/text/text.cxx
index 6f3aff9faa32..32debf5091db 100644
--- a/sw/qa/core/text/text.cxx
+++ b/sw/qa/core/text/text.cxx
@@ -18,22 +18,11 @@ char const DATA_DIRECTORY[] = "/sw/qa/core/text/data/";
 /// Covers sw/source/core/text/ fixes.
 class SwCoreTextTest : public SwModelTestBase
 {
-public:
-    SwDoc* createDoc(const char* pName = nullptr);
 };
 
-SwDoc* SwCoreTextTest::createDoc(const char* pName)
-{
-    load(DATA_DIRECTORY, pName);
-
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    return pTextDoc->GetDocShell()->GetDoc();
-}
-
 CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testFootnoteConnect)
 {
-    SwDoc* pDoc = createDoc("footnote-connect.fodt");
+    SwDoc* pDoc = createSwDoc(DATA_DIRECTORY, "footnote-connect.fodt");
     SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
     // Jump to the start of the next page.
     pWrtShell->SttNxtPg();
diff --git a/sw/qa/inc/swmodeltestbase.hxx b/sw/qa/inc/swmodeltestbase.hxx
index 8265801f36f8..a0170896ac80 100644
--- a/sw/qa/inc/swmodeltestbase.hxx
+++ b/sw/qa/inc/swmodeltestbase.hxx
@@ -1030,6 +1030,18 @@ protected:
         // reqif-xhtml
         xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("reqif-xhtml"), 
BAD_CAST("http://www.w3.org/1999/xhtml";));
     }
+
+    SwDoc* createSwDoc(const OUString& rDataDirectory = OUString(), const 
char* pName = nullptr)
+    {
+        if (rDataDirectory.isEmpty() || !pName)
+            loadURL("private:factory/swriter", nullptr);
+        else
+            load(rDataDirectory, pName);
+
+        SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
+        CPPUNIT_ASSERT(pTextDoc);
+        return pTextDoc->GetDocShell()->GetDoc();
+    }
 };
 
 /**
diff --git a/sw/qa/uibase/dochdl/dochdl.cxx b/sw/qa/uibase/dochdl/dochdl.cxx
index 26f8fe502e50..1de97968da2e 100644
--- a/sw/qa/uibase/dochdl/dochdl.cxx
+++ b/sw/qa/uibase/dochdl/dochdl.cxx
@@ -17,23 +17,12 @@
 /// Covers sw/source/uibase/dochdl/ fixes.
 class SwUibaseDochdlTest : public SwModelTestBase
 {
-public:
-    SwDoc* createDoc();
 };
 
-SwDoc* SwUibaseDochdlTest::createDoc()
-{
-    loadURL("private:factory/swriter", nullptr);
-
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    return pTextDoc->GetDocShell()->GetDoc();
-}
-
 CPPUNIT_TEST_FIXTURE(SwUibaseDochdlTest, testSelectPasteFormat)
 {
     // Create a new document and cut a character.
-    SwDoc* pDoc = createDoc();
+    SwDoc* pDoc = createSwDoc();
     SwDocShell* pDocShell = pDoc->GetDocShell();
     SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
     pWrtShell->Insert2("x");
diff --git a/sw/qa/uibase/frmdlg/frmdlg.cxx b/sw/qa/uibase/frmdlg/frmdlg.cxx
index 3700abb9d946..39d55be0a880 100644
--- a/sw/qa/uibase/frmdlg/frmdlg.cxx
+++ b/sw/qa/uibase/frmdlg/frmdlg.cxx
@@ -16,26 +16,12 @@ char const DATA_DIRECTORY[] = "/sw/qa/uibase/frmdlg/data/";
 /// Covers sw/source/uibase/frmdlg/ fixes.
 class SwUibaseFrmdlgTest : public SwModelTestBase
 {
-public:
-    void createDoc(const char* pName = nullptr);
 };
 
-void SwUibaseFrmdlgTest::createDoc(const char* pName)
-{
-    if (!pName)
-    {
-        loadURL("private:factory/swriter", nullptr);
-    }
-    else
-    {
-        load(DATA_DIRECTORY, pName);
-    }
-}
-
 CPPUNIT_TEST_FIXTURE(SwUibaseFrmdlgTest, testWrappedMathObject)
 {
     // The document includes a Math object with explicit wrapping.
-    createDoc("wrapped-math-object.docx");
+    load(DATA_DIRECTORY, "wrapped-math-object.docx");
     uno::Reference<drawing::XShape> xMath = getShape(1);
 
     // Without the accompanying fix in place, this test would have failed with:
diff --git a/sw/qa/uibase/shells/shells.cxx b/sw/qa/uibase/shells/shells.cxx
index 446fbacb2278..e8fc09418713 100644
--- a/sw/qa/uibase/shells/shells.cxx
+++ b/sw/qa/uibase/shells/shells.cxx
@@ -31,25 +31,11 @@ char const DATA_DIRECTORY[] = "/sw/qa/uibase/shells/data/";
 /// Covers sw/source/uibase/shells/ fixes.
 class SwUibaseShellsTest : public SwModelTestBase
 {
-public:
-    SwDoc* createDoc(const char* pName = nullptr);
 };
 
-SwDoc* SwUibaseShellsTest::createDoc(const char* pName)
-{
-    if (!pName)
-        loadURL("private:factory/swriter", nullptr);
-    else
-        load(DATA_DIRECTORY, pName);
-
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    return pTextDoc->GetDocShell()->GetDoc();
-}
-
 CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testTdf130179)
 {
-    SwDoc* pDoc = createDoc();
+    SwDoc* pDoc = createSwDoc();
     IDocumentContentOperations& rIDCO = pDoc->getIDocumentContentOperations();
     SwCursorShell* pShell(pDoc->GetEditShell());
     SfxItemSet aFrameSet(pDoc->GetAttrPool(), svl::Items<RES_FRMATR_BEGIN, 
RES_FRMATR_END - 1>{});
@@ -80,7 +66,7 @@ CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, 
testShapeTextAlignment)
 // FIXME find out why this fails on macOS/Windows
 #if !defined(MACOSX) && !defined(_WIN32)
     // Create a document with a rectangle in it.
-    SwDoc* pDoc = createDoc();
+    SwDoc* pDoc = createSwDoc();
     SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
     Point aStartPos(1000, 1000);
     pWrtShell->BeginCreate(static_cast<sal_uInt16>(OBJ_RECT), aStartPos);
@@ -121,7 +107,7 @@ CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, 
testOleSavePreviewUpdate)
 {
     // Load a document with 2 charts in it. The second is down enough that you 
have to scroll to
     // trigger its rendering. Previews are missing for both.
-    createDoc("ole-save-preview-update.odt");
+    load(DATA_DIRECTORY, "ole-save-preview-update.odt");
 
     // Explicitly update OLE previews, etc.
     dispatchCommand(mxComponent, ".uno:UpdateAll", {});
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to