[Libreoffice-commits] core.git: sw/qa

Stephan Bergmann (via logerrit) logerrit at kemper.freedesktop.org
Fri Mar 20 06:37:50 UTC 2020


 sw/qa/api/SwXTextField.cxx |   20 ++++++++++++++++----
 sw/qa/api/SwXTextTable.cxx |   28 +++++++++++++++++++++++-----
 2 files changed, 39 insertions(+), 9 deletions(-)

New commits:
commit 20ed81fd42cf8079c11c2b18973b9504a679e49c
Author:     Stephan Bergmann <sbergman at redhat.com>
AuthorDate: Thu Mar 19 23:36:21 2020 +0100
Commit:     Stephan Bergmann <sbergman at redhat.com>
CommitDate: Fri Mar 20 07:37:13 2020 +0100

    Make individual tests clean up after themselves
    
    ...instead of relying on the final SwXTextTable testDisposedByDesktopTerminate
    to dispose all opened documents
    
    Change-Id: Ia0f44ab96e8ee2ee8fc6479fa23403ab8abf52da
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/90768
    Tested-by: Jenkins
    Reviewed-by: Stephan Bergmann <sbergman at redhat.com>

diff --git a/sw/qa/api/SwXTextField.cxx b/sw/qa/api/SwXTextField.cxx
index 1de775d1e3d7..8273795a16f7 100644
--- a/sw/qa/api/SwXTextField.cxx
+++ b/sw/qa/api/SwXTextField.cxx
@@ -40,6 +40,7 @@ struct SwXTextField final : public test::BootstrapFixture,
                             public apitest::XComponent
 {
     virtual void setUp() override;
+    void tearDown() override;
 
     Reference<XInterface> init() override;
     void triggerDesktopTerminate() override;
@@ -49,6 +50,9 @@ struct SwXTextField final : public test::BootstrapFixture,
     CPPUNIT_TEST(testRemoveEventListener);
     //CPPUNIT_TEST(testDisposedByDesktopTerminate);
     CPPUNIT_TEST_SUITE_END();
+
+private:
+    css::uno::Reference<css::lang::XComponent> component_;
 };
 
 void SwXTextField::setUp()
@@ -58,14 +62,22 @@ void SwXTextField::setUp()
         frame::Desktop::create(comphelper::getComponentContext(getMultiServiceFactory())));
 }
 
+void SwXTextField::tearDown()
+{
+    if (component_.is())
+    {
+        component_->dispose();
+    }
+}
+
 void SwXTextField::triggerDesktopTerminate() { mxDesktop->terminate(); }
 
 Reference<XInterface> SwXTextField::init()
 {
-    auto xComponent = loadFromDesktop("private:factory/swriter", "com.sun.star.text.TextDocument");
-    CPPUNIT_ASSERT(xComponent.is());
-    Reference<text::XTextDocument> xTextDocument(xComponent, UNO_QUERY_THROW);
-    Reference<lang::XMultiServiceFactory> xMSF(xComponent, UNO_QUERY_THROW);
+    component_ = loadFromDesktop("private:factory/swriter", "com.sun.star.text.TextDocument");
+    CPPUNIT_ASSERT(component_.is());
+    Reference<text::XTextDocument> xTextDocument(component_, UNO_QUERY_THROW);
+    Reference<lang::XMultiServiceFactory> xMSF(component_, UNO_QUERY_THROW);
 
     Reference<XPropertySet> xFieldMaster(
         xMSF->createInstance("com.sun.star.text.FieldMaster.Database"), UNO_QUERY_THROW);
diff --git a/sw/qa/api/SwXTextTable.cxx b/sw/qa/api/SwXTextTable.cxx
index bc4e0271ccf4..ed1bc0670251 100644
--- a/sw/qa/api/SwXTextTable.cxx
+++ b/sw/qa/api/SwXTextTable.cxx
@@ -12,7 +12,7 @@
 #include <unotest/macros_test.hxx>
 
 #include <com/sun/star/frame/Desktop.hpp>
-
+#include <com/sun/star/lang/DisposedException.hpp>
 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
 
 #include <com/sun/star/text/XTextDocument.hpp>
@@ -36,6 +36,7 @@ struct SwXTextTable final : public test::BootstrapFixture,
                             public apitest::XComponent
 {
     virtual void setUp() override;
+    void tearDown() override;
 
     Reference<XInterface> init() override;
     void triggerDesktopTerminate() override;
@@ -45,6 +46,9 @@ struct SwXTextTable final : public test::BootstrapFixture,
     CPPUNIT_TEST(testRemoveEventListener);
     CPPUNIT_TEST(testDisposedByDesktopTerminate);
     CPPUNIT_TEST_SUITE_END();
+
+private:
+    css::uno::Reference<css::lang::XComponent> component_;
 };
 
 void SwXTextTable::setUp()
@@ -54,14 +58,28 @@ void SwXTextTable::setUp()
         frame::Desktop::create(comphelper::getComponentContext(getMultiServiceFactory())));
 }
 
+void SwXTextTable::tearDown()
+{
+    if (component_.is())
+    {
+        try
+        {
+            component_->dispose();
+        }
+        catch (css::lang::DisposedException&) // thrown by testDisposedByDesktopTerminate
+        {
+        }
+    }
+}
+
 void SwXTextTable::triggerDesktopTerminate() { mxDesktop->terminate(); }
 
 Reference<XInterface> SwXTextTable::init()
 {
-    auto xComponent = loadFromDesktop("private:factory/swriter", "com.sun.star.text.TextDocument");
-    CPPUNIT_ASSERT(xComponent.is());
-    Reference<text::XTextDocument> xTextDocument(xComponent, UNO_QUERY_THROW);
-    Reference<lang::XMultiServiceFactory> xMSF(xComponent, UNO_QUERY_THROW);
+    component_ = loadFromDesktop("private:factory/swriter", "com.sun.star.text.TextDocument");
+    CPPUNIT_ASSERT(component_.is());
+    Reference<text::XTextDocument> xTextDocument(component_, UNO_QUERY_THROW);
+    Reference<lang::XMultiServiceFactory> xMSF(component_, UNO_QUERY_THROW);
     Reference<text::XText> xText = xTextDocument->getText();
     Reference<text::XTextCursor> xCursor = xText->createTextCursor();
     Reference<text::XTextTable> xTable(xMSF->createInstance("com.sun.star.text.TextTable"),


More information about the Libreoffice-commits mailing list