From 940b4d1848e8c70ab7642901a68594e8016caffc Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 18:51:28 +0200 Subject: Adding upstream version 1:7.0.4. Signed-off-by: Daniel Baumann --- sw/qa/api/SwXDocumentIndex.cxx | 123 ++++++++++++++++++++++++++++++++++++++ sw/qa/api/SwXDocumentSettings.cxx | 94 +++++++++++++++++++++++++++++ sw/qa/api/SwXTextField.cxx | 100 +++++++++++++++++++++++++++++++ sw/qa/api/SwXTextFrame.cxx | 100 +++++++++++++++++++++++++++++++ sw/qa/api/SwXTextTable.cxx | 89 +++++++++++++++++++++++++++ sw/qa/api/terminate.cxx | 76 +++++++++++++++++++++++ 6 files changed, 582 insertions(+) create mode 100644 sw/qa/api/SwXDocumentIndex.cxx create mode 100644 sw/qa/api/SwXDocumentSettings.cxx create mode 100644 sw/qa/api/SwXTextField.cxx create mode 100644 sw/qa/api/SwXTextFrame.cxx create mode 100644 sw/qa/api/SwXTextTable.cxx create mode 100644 sw/qa/api/terminate.cxx (limited to 'sw/qa/api') diff --git a/sw/qa/api/SwXDocumentIndex.cxx b/sw/qa/api/SwXDocumentIndex.cxx new file mode 100644 index 000000000..e76db3512 --- /dev/null +++ b/sw/qa/api/SwXDocumentIndex.cxx @@ -0,0 +1,123 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +#include +#include +#include +#include +#include +#include + +#include + +using namespace css; + +namespace +{ +/** + * Test for Java API test of file com.sun.star.comp.office.SwXDocumentIndex.csv + */ +class SwXDocumentIndex final : public test::BootstrapFixture, + public unotest::MacrosTest, + public apitest::XDocumentIndex, + public apitest::BaseIndex, + public apitest::TextDocumentIndex, + public apitest::XTextContent, + public apitest::XServiceInfo, + public apitest::XComponent +{ + uno::Reference mxTextDocument; + uno::Reference mxTextRange; + uno::Reference mxTextContent; + +public: + virtual void setUp() override; + virtual void tearDown() override; + + SwXDocumentIndex() + : apitest::XServiceInfo("SwXDocumentIndex", "com.sun.star.text.BaseIndex"){}; + uno::Reference init() override; + uno::Reference getTextRange() override; + uno::Reference getTextContent() override; + bool isAttachSupported() override { return true; } + uno::Reference getTextDocument() override { return mxTextDocument; } + void triggerDesktopTerminate() override {} + + CPPUNIT_TEST_SUITE(SwXDocumentIndex); + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + CPPUNIT_TEST(testUpdate); + CPPUNIT_TEST(testBaseIndexProperties); + CPPUNIT_TEST(testDocumentIndexProperties); + CPPUNIT_TEST(testAttach); + CPPUNIT_TEST(testGetAnchor); + CPPUNIT_TEST(testAddEventListener); + CPPUNIT_TEST(testRemoveEventListener); + CPPUNIT_TEST_SUITE_END(); +}; + +void SwXDocumentIndex::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 SwXDocumentIndex::tearDown() +{ + if (mxTextDocument.is()) + mxTextDocument->dispose(); + + test::BootstrapFixture::tearDown(); +} + +uno::Reference SwXDocumentIndex::init() +{ + uno::Reference xMSF(mxTextDocument, uno::UNO_QUERY_THROW); + uno::Reference xDocumentIndex( + xMSF->createInstance("com.sun.star.text.DocumentIndex"), uno::UNO_QUERY_THROW); + auto xText = getTextDocument()->getText(); + auto xTextCursor = xText->createTextCursor(); + CPPUNIT_ASSERT(xTextCursor.is()); + xText->insertTextContent(xTextCursor, xDocumentIndex, false); + xTextCursor->gotoEnd(false); + mxTextRange = uno::Reference(xTextCursor, uno::UNO_QUERY_THROW); + mxTextContent = uno::Reference( + xMSF->createInstance("com.sun.star.text.DocumentIndex"), uno::UNO_QUERY_THROW); + return xDocumentIndex; +} + +uno::Reference SwXDocumentIndex::getTextRange() { return mxTextRange; } + +uno::Reference SwXDocumentIndex::getTextContent() { return mxTextContent; } + +CPPUNIT_TEST_SUITE_REGISTRATION(SwXDocumentIndex); +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/qa/api/SwXDocumentSettings.cxx b/sw/qa/api/SwXDocumentSettings.cxx new file mode 100644 index 000000000..5f91f645a --- /dev/null +++ b/sw/qa/api/SwXDocumentSettings.cxx @@ -0,0 +1,94 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include +#include +#include +#include +#include + +#include + +#include + +#include +#include + +#include + +using namespace css; + +namespace +{ +/** + * Test for Java API test of file com.sun.star.comp.Writer.DocumentSettings.csv + */ +class SwXDocumentSettings final : public test::BootstrapFixture, + public unotest::MacrosTest, + public apitest::TextDocumentSettings, + public apitest::TextSettings, + public apitest::TextPrinterSettings, + public apitest::XServiceInfo +{ +private: + uno::Reference mxComponent; + +public: + virtual void setUp() override; + virtual void tearDown() override; + + SwXDocumentSettings() + : apitest::XServiceInfo("SwXDocumentSettings", "com.sun.star.text.DocumentSettings"){}; + uno::Reference init() override; + + CPPUNIT_TEST_SUITE(SwXDocumentSettings); + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + CPPUNIT_TEST(testDocumentSettingsProperties); + CPPUNIT_TEST(testSettingsProperties); + CPPUNIT_TEST(testPrinterSettingsProperties); + CPPUNIT_TEST_SUITE_END(); +}; + +void SwXDocumentSettings::setUp() +{ + test::BootstrapFixture::setUp(); + + mxDesktop.set(frame::Desktop::create(mxComponentContext)); +} + +void SwXDocumentSettings::tearDown() +{ + if (mxComponent.is()) + mxComponent->dispose(); + + test::BootstrapFixture::tearDown(); +} + +uno::Reference SwXDocumentSettings::init() +{ + mxComponent = loadFromDesktop("private:factory/swriter", "com.sun.star.text.TextDocument"); + CPPUNIT_ASSERT(mxComponent.is()); + + uno::Reference xTextDocument(mxComponent, uno::UNO_QUERY_THROW); + uno::Reference xFactory(xTextDocument, uno::UNO_QUERY_THROW); + + uno::Reference xDocumentSettings( + xFactory->createInstance("com.sun.star.text.DocumentSettings"), uno::UNO_SET_THROW); + + return xDocumentSettings; +} + +CPPUNIT_TEST_SUITE_REGISTRATION(SwXDocumentSettings); + +} // end anonymous namespace + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/qa/api/SwXTextField.cxx b/sw/qa/api/SwXTextField.cxx new file mode 100644 index 000000000..272e0b9f7 --- /dev/null +++ b/sw/qa/api/SwXTextField.cxx @@ -0,0 +1,100 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include +#include + +#include + +#include + +#include + +#include +#include +#include +#include +#include +#include + +#include + +using namespace css; +using namespace css::uno; +using namespace css::beans; + +namespace +{ +/** + * Initial tests for SwXTextField. + */ +struct SwXTextField final : public test::BootstrapFixture, + public unotest::MacrosTest, + public apitest::XComponent +{ + virtual void setUp() override; + void tearDown() override; + + Reference init() override; + void triggerDesktopTerminate() override; + + CPPUNIT_TEST_SUITE(SwXTextField); + CPPUNIT_TEST(testAddEventListener); + CPPUNIT_TEST(testRemoveEventListener); + CPPUNIT_TEST_SUITE_END(); + +private: + css::uno::Reference component_; +}; + +void SwXTextField::setUp() +{ + test::BootstrapFixture::setUp(); + mxDesktop.set( + frame::Desktop::create(comphelper::getComponentContext(getMultiServiceFactory()))); +} + +void SwXTextField::tearDown() +{ + if (component_.is()) + { + component_->dispose(); + } +} + +void SwXTextField::triggerDesktopTerminate() { mxDesktop->terminate(); } + +Reference SwXTextField::init() +{ + component_ = loadFromDesktop("private:factory/swriter", "com.sun.star.text.TextDocument"); + CPPUNIT_ASSERT(component_.is()); + Reference xTextDocument(component_, UNO_QUERY_THROW); + Reference xMSF(component_, UNO_QUERY_THROW); + + Reference xFieldMaster( + xMSF->createInstance("com.sun.star.text.FieldMaster.Database"), UNO_QUERY_THROW); + xFieldMaster->setPropertyValue("DataBaseName", makeAny(OUString("Address Book File"))); + xFieldMaster->setPropertyValue("DataTableName", makeAny(OUString("address"))); + xFieldMaster->setPropertyValue("DataColumnName", makeAny(OUString("FIRSTNAME"))); + + Reference xField( + xMSF->createInstance("com.sun.star.text.TextField.Database"), UNO_QUERY_THROW); + xField->attachTextFieldMaster(xFieldMaster); + Reference xText = xTextDocument->getText(); + Reference xCursor = xText->createTextCursor(); + Reference xFieldAsContent(xField, UNO_QUERY_THROW); + xText->insertTextContent(xCursor, xFieldAsContent, false); + return Reference(xField, UNO_QUERY_THROW); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(SwXTextField); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/qa/api/SwXTextFrame.cxx b/sw/qa/api/SwXTextFrame.cxx new file mode 100644 index 000000000..09237028a --- /dev/null +++ b/sw/qa/api/SwXTextFrame.cxx @@ -0,0 +1,100 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +#include +#include +#include +#include +#include +#include + +#include + +using namespace css; + +namespace +{ +/** + * Test for Java API test of file com.sun.star.comp.office.SwXTextFrame.csv + */ +class SwXTextFrame final : public test::BootstrapFixture, + public unotest::MacrosTest, + 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; } + void triggerDesktopTerminate() override { mxDesktop->terminate(); } + + CPPUNIT_TEST_SUITE(SwXTextFrame); + CPPUNIT_TEST(testGetImplementationName); + CPPUNIT_TEST(testGetSupportedServiceNames); + CPPUNIT_TEST(testSupportsService); + CPPUNIT_TEST(testAddEventListener); + CPPUNIT_TEST(testRemoveEventListener); + 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); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/qa/api/SwXTextTable.cxx b/sw/qa/api/SwXTextTable.cxx new file mode 100644 index 000000000..37c860065 --- /dev/null +++ b/sw/qa/api/SwXTextTable.cxx @@ -0,0 +1,89 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include + +using namespace css; +using namespace css::uno; + +namespace +{ +/** + * Initial tests for SwXTextTable. + */ +struct SwXTextTable final : public test::BootstrapFixture, + public unotest::MacrosTest, + public apitest::XComponent +{ + virtual void setUp() override; + void tearDown() override; + + Reference init() override; + void triggerDesktopTerminate() override; + + CPPUNIT_TEST_SUITE(SwXTextTable); + CPPUNIT_TEST(testAddEventListener); + CPPUNIT_TEST(testRemoveEventListener); + CPPUNIT_TEST_SUITE_END(); + +private: + css::uno::Reference component_; +}; + +void SwXTextTable::setUp() +{ + test::BootstrapFixture::setUp(); + mxDesktop.set( + frame::Desktop::create(comphelper::getComponentContext(getMultiServiceFactory()))); +} + +void SwXTextTable::tearDown() +{ + if (component_.is()) + { + component_->dispose(); + } +} + +void SwXTextTable::triggerDesktopTerminate() { mxDesktop->terminate(); } + +Reference SwXTextTable::init() +{ + component_ = loadFromDesktop("private:factory/swriter", "com.sun.star.text.TextDocument"); + CPPUNIT_ASSERT(component_.is()); + Reference xTextDocument(component_, UNO_QUERY_THROW); + Reference xMSF(component_, UNO_QUERY_THROW); + Reference xText = xTextDocument->getText(); + Reference xCursor = xText->createTextCursor(); + Reference xTable(xMSF->createInstance("com.sun.star.text.TextTable"), + UNO_QUERY_THROW); + xTable->initialize(4, 3); + xText->insertTextContent(xCursor, xTable, false); + CPPUNIT_ASSERT(xCursor.is()); + return Reference(xTable, UNO_QUERY_THROW); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(SwXTextTable); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/qa/api/terminate.cxx b/sw/qa/api/terminate.cxx new file mode 100644 index 000000000..5f077d0aa --- /dev/null +++ b/sw/qa/api/terminate.cxx @@ -0,0 +1,76 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +class TerminateTest final : public test::BootstrapFixture, + public unotest::MacrosTest, + public apitest::XComponent +{ +public: + void setUp() override; + + css::uno::Reference init() override; + + void triggerDesktopTerminate() override; + + CPPUNIT_TEST_SUITE(TerminateTest); + CPPUNIT_TEST(testDisposedByDesktopTerminate); + CPPUNIT_TEST_SUITE_END(); +}; + +void TerminateTest::setUp() +{ + test::BootstrapFixture::setUp(); + mxDesktop.set( + css::frame::Desktop::create(comphelper::getComponentContext(getMultiServiceFactory()))); +} + +css::uno::Reference TerminateTest::init() +{ + auto const component + = loadFromDesktop("private:factory/swriter", "com.sun.star.text.TextDocument"); + CPPUNIT_ASSERT(component.is()); + css::uno::Reference xTextDocument(component, + css::uno::UNO_QUERY_THROW); + css::uno::Reference xMSF(component, css::uno::UNO_QUERY_THROW); + css::uno::Reference xText = xTextDocument->getText(); + css::uno::Reference xCursor = xText->createTextCursor(); + css::uno::Reference xTable( + xMSF->createInstance("com.sun.star.text.TextTable"), css::uno::UNO_QUERY_THROW); + xTable->initialize(4, 3); + xText->insertTextContent(xCursor, xTable, false); + CPPUNIT_ASSERT(xCursor.is()); + return css::uno::Reference(xTable, css::uno::UNO_QUERY_THROW); +} + +void TerminateTest::triggerDesktopTerminate() { mxDesktop->terminate(); } + +CPPUNIT_TEST_SUITE_REGISTRATION(TerminateTest); + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ -- cgit v1.2.3