From 191814f47afd2dd6340e1da4499ca794d6dff268 Mon Sep 17 00:00:00 2001 From: Tomaž Vajngerl Date: Mon, 26 Jun 2023 21:22:35 +0900 Subject: sw: simplify SwXTextFrame UNO API test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit make it more inline to Calc UNO API tests Change-Id: I92e3f4f9b7286ea402cc0e869fec24ee9d2c05e6 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153611 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl --- sw/qa/api/SwXTextFrame.cxx | 75 ++++++++++++++++++---------------------------- 1 file changed, 29 insertions(+), 46 deletions(-) (limited to 'sw/qa/api') diff --git a/sw/qa/api/SwXTextFrame.cxx b/sw/qa/api/SwXTextFrame.cxx index c1fa862fb6e1..5f356fdbfb97 100644 --- a/sw/qa/api/SwXTextFrame.cxx +++ b/sw/qa/api/SwXTextFrame.cxx @@ -7,15 +7,12 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include +#include #include #include -#include #include - #include - #include #include #include @@ -28,21 +25,39 @@ namespace /** * Test for Java API test of file com.sun.star.comp.office.SwXTextFrame.csv */ -class SwXTextFrame final : public test::BootstrapFixture, - public unotest::MacrosTest, +class SwXTextFrame final : public UnoApiTest, public apitest::XServiceInfo, public apitest::XComponent { - uno::Reference mxTextDocument; - public: - virtual void setUp() override; - virtual void tearDown() override; - SwXTextFrame() - : apitest::XServiceInfo("SwXTextFrame", "com.sun.star.text.TextFrame"){}; - uno::Reference init() override; - const uno::Reference& getTextDocument() const { return mxTextDocument; } + : UnoApiTest("") + , apitest::XServiceInfo("SwXTextFrame", "com.sun.star.text.TextFrame") + { + } + + virtual void setUp() override + { + UnoApiTest::setUp(); + mxDesktop.set(frame::Desktop::create(mxComponentContext)); + mxComponent = loadFromDesktop("private:factory/swriter"); + CPPUNIT_ASSERT(mxComponent.is()); + } + + uno::Reference init() override + { + uno::Reference xMSF(mxComponent, uno::UNO_QUERY_THROW); + uno::Reference xTextDocument(mxComponent, uno::UNO_QUERY_THROW); + uno::Reference xTextFrame( + xMSF->createInstance("com.sun.star.text.TextFrame"), uno::UNO_QUERY_THROW); + auto xText = xTextDocument->getText(); + auto xTextCursor = xText->createTextCursor(); + CPPUNIT_ASSERT(xTextCursor.is()); + xText->insertTextContent(xTextCursor, xTextFrame, false); + xTextCursor->gotoEnd(false); + return xTextFrame; + } + void triggerDesktopTerminate() override { mxDesktop->terminate(); } CPPUNIT_TEST_SUITE(SwXTextFrame); @@ -54,38 +69,6 @@ public: CPPUNIT_TEST_SUITE_END(); }; -void SwXTextFrame::setUp() -{ - test::BootstrapFixture::setUp(); - - mxDesktop.set(frame::Desktop::create(mxComponentContext)); - mxTextDocument = uno::Reference( - loadFromDesktop("private:factory/swriter", "com.sun.star.text.TextDocument"), - uno::UNO_QUERY_THROW); - CPPUNIT_ASSERT(mxTextDocument.is()); -} - -void SwXTextFrame::tearDown() -{ - if (mxTextDocument.is()) - mxTextDocument->dispose(); - - test::BootstrapFixture::tearDown(); -} - -uno::Reference SwXTextFrame::init() -{ - uno::Reference xMSF(mxTextDocument, uno::UNO_QUERY_THROW); - uno::Reference xTextFrame(xMSF->createInstance("com.sun.star.text.TextFrame"), - uno::UNO_QUERY_THROW); - auto xText = getTextDocument()->getText(); - auto xTextCursor = xText->createTextCursor(); - CPPUNIT_ASSERT(xTextCursor.is()); - xText->insertTextContent(xTextCursor, xTextFrame, false); - xTextCursor->gotoEnd(false); - return xTextFrame; -} - CPPUNIT_TEST_SUITE_REGISTRATION(SwXTextFrame); } -- cgit