diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:06:44 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:06:44 +0000 |
commit | ed5640d8b587fbcfed7dd7967f3de04b37a76f26 (patch) | |
tree | 7a5f7c6c9d02226d7471cb3cc8fbbf631b415303 /sw/qa/api | |
parent | Initial commit. (diff) | |
download | libreoffice-upstream.tar.xz libreoffice-upstream.zip |
Adding upstream version 4:7.4.7.upstream/4%7.4.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'sw/qa/api')
-rw-r--r-- | sw/qa/api/SwXDocumentIndex.cxx | 121 | ||||
-rw-r--r-- | sw/qa/api/SwXDocumentSettings.cxx | 90 | ||||
-rw-r--r-- | sw/qa/api/SwXTextField.cxx | 98 | ||||
-rw-r--r-- | sw/qa/api/SwXTextFrame.cxx | 92 | ||||
-rw-r--r-- | sw/qa/api/SwXTextTable.cxx | 86 | ||||
-rw-r--r-- | sw/qa/api/terminate.cxx | 75 |
6 files changed, 562 insertions, 0 deletions
diff --git a/sw/qa/api/SwXDocumentIndex.cxx b/sw/qa/api/SwXDocumentIndex.cxx new file mode 100644 index 000000000..32fb66921 --- /dev/null +++ b/sw/qa/api/SwXDocumentIndex.cxx @@ -0,0 +1,121 @@ +/* -*- 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 <test/bootstrapfixture.hxx> +#include <test/lang/xserviceinfo.hxx> +#include <test/lang/xcomponent.hxx> +#include <test/text/baseindex.hxx> +#include <test/text/textdocumentindex.hxx> +#include <test/text/xdocumentindex.hxx> +#include <test/text/xtextcontent.hxx> +#include <unotest/macros_test.hxx> + +#include <com/sun/star/frame/Desktop.hpp> + +#include <com/sun/star/lang/XMultiServiceFactory.hpp> + +#include <com/sun/star/text/XTextDocument.hpp> +#include <com/sun/star/text/XTextContent.hpp> +#include <com/sun/star/text/XText.hpp> +#include <com/sun/star/text/XTextCursor.hpp> +#include <com/sun/star/text/XTextRange.hpp> +#include <com/sun/star/text/XDocumentIndex.hpp> + +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<text::XTextDocument> mxTextDocument; + uno::Reference<text::XTextRange> mxTextRange; + uno::Reference<text::XTextContent> mxTextContent; + +public: + virtual void setUp() override; + virtual void tearDown() override; + + SwXDocumentIndex() + : apitest::XServiceInfo("SwXDocumentIndex", "com.sun.star.text.BaseIndex"){}; + uno::Reference<uno::XInterface> init() override; + uno::Reference<text::XTextRange> getTextRange() override; + uno::Reference<text::XTextContent> getTextContent() override; + bool isAttachSupported() override { return true; } + uno::Reference<text::XTextDocument> 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<text::XTextDocument>( + 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<uno::XInterface> SwXDocumentIndex::init() +{ + uno::Reference<lang::XMultiServiceFactory> xMSF(mxTextDocument, uno::UNO_QUERY_THROW); + uno::Reference<text::XDocumentIndex> 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<text::XTextRange>(xTextCursor, uno::UNO_QUERY_THROW); + mxTextContent = uno::Reference<text::XTextContent>( + xMSF->createInstance("com.sun.star.text.DocumentIndex"), uno::UNO_QUERY_THROW); + return xDocumentIndex; +} + +uno::Reference<text::XTextRange> SwXDocumentIndex::getTextRange() { return mxTextRange; } + +uno::Reference<text::XTextContent> 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..da2b366da --- /dev/null +++ b/sw/qa/api/SwXDocumentSettings.cxx @@ -0,0 +1,90 @@ +/* -*- 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 <test/bootstrapfixture.hxx> +#include <test/lang/xserviceinfo.hxx> +#include <test/text/textdocumentsettings.hxx> +#include <test/text/textprintersettings.hxx> +#include <test/text/textsettings.hxx> +#include <unotest/macros_test.hxx> + +#include <com/sun/star/frame/Desktop.hpp> + +#include <com/sun/star/lang/XMultiServiceFactory.hpp> + +#include <com/sun/star/text/XTextDocument.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +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<lang::XComponent> mxComponent; + +public: + virtual void setUp() override; + virtual void tearDown() override; + + SwXDocumentSettings() + : apitest::XServiceInfo("SwXDocumentSettings", "com.sun.star.text.DocumentSettings"){}; + uno::Reference<uno::XInterface> 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<uno::XInterface> SwXDocumentSettings::init() +{ + mxComponent = loadFromDesktop("private:factory/swriter", "com.sun.star.text.TextDocument"); + uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY_THROW); + uno::Reference<lang::XMultiServiceFactory> xFactory(xTextDocument, uno::UNO_QUERY_THROW); + + uno::Reference<uno::XInterface> 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..5c8464233 --- /dev/null +++ b/sw/qa/api/SwXTextField.cxx @@ -0,0 +1,98 @@ +/* -*- 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 <test/bootstrapfixture.hxx> +#include <test/lang/xcomponent.hxx> +#include <unotest/macros_test.hxx> + +#include <com/sun/star/frame/Desktop.hpp> + +#include <com/sun/star/lang/XMultiServiceFactory.hpp> + +#include <com/sun/star/beans/XPropertySet.hpp> + +#include <com/sun/star/text/XTextDocument.hpp> +#include <com/sun/star/text/XTextContent.hpp> +#include <com/sun/star/text/XText.hpp> +#include <com/sun/star/text/XDependentTextField.hpp> +#include <com/sun/star/text/XTextCursor.hpp> + +#include <comphelper/processfactory.hxx> + +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<XInterface> init() override; + void triggerDesktopTerminate() override; + + CPPUNIT_TEST_SUITE(SwXTextField); + CPPUNIT_TEST(testAddEventListener); + CPPUNIT_TEST(testRemoveEventListener); + CPPUNIT_TEST_SUITE_END(); + +private: + css::uno::Reference<css::lang::XComponent> 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<XInterface> SwXTextField::init() +{ + component_ = loadFromDesktop("private:factory/swriter", "com.sun.star.text.TextDocument"); + 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); + xFieldMaster->setPropertyValue("DataBaseName", Any(OUString("Address Book File"))); + xFieldMaster->setPropertyValue("DataTableName", Any(OUString("address"))); + xFieldMaster->setPropertyValue("DataColumnName", Any(OUString("FIRSTNAME"))); + + Reference<text::XDependentTextField> xField( + xMSF->createInstance("com.sun.star.text.TextField.Database"), UNO_QUERY_THROW); + xField->attachTextFieldMaster(xFieldMaster); + Reference<text::XText> xText = xTextDocument->getText(); + Reference<text::XTextCursor> xCursor = xText->createTextCursor(); + Reference<text::XTextContent> xFieldAsContent(xField, UNO_QUERY_THROW); + xText->insertTextContent(xCursor, xFieldAsContent, false); + return Reference<XInterface>(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..c1fa862fb --- /dev/null +++ b/sw/qa/api/SwXTextFrame.cxx @@ -0,0 +1,92 @@ +/* -*- 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 <test/bootstrapfixture.hxx> +#include <test/lang/xserviceinfo.hxx> +#include <test/lang/xcomponent.hxx> +#include <unotest/macros_test.hxx> + +#include <com/sun/star/frame/Desktop.hpp> + +#include <com/sun/star/lang/XMultiServiceFactory.hpp> + +#include <com/sun/star/text/XTextDocument.hpp> +#include <com/sun/star/text/XText.hpp> +#include <com/sun/star/text/XTextCursor.hpp> +#include <com/sun/star/text/XTextFrame.hpp> + +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<text::XTextDocument> mxTextDocument; + +public: + virtual void setUp() override; + virtual void tearDown() override; + + SwXTextFrame() + : apitest::XServiceInfo("SwXTextFrame", "com.sun.star.text.TextFrame"){}; + uno::Reference<uno::XInterface> init() override; + const uno::Reference<text::XTextDocument>& 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<text::XTextDocument>( + 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<uno::XInterface> SwXTextFrame::init() +{ + uno::Reference<lang::XMultiServiceFactory> xMSF(mxTextDocument, uno::UNO_QUERY_THROW); + uno::Reference<text::XTextFrame> 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..229583ebc --- /dev/null +++ b/sw/qa/api/SwXTextTable.cxx @@ -0,0 +1,86 @@ +/* -*- 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 <test/bootstrapfixture.hxx> +#include <test/lang/xcomponent.hxx> +#include <unotest/macros_test.hxx> + +#include <com/sun/star/frame/Desktop.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> + +#include <com/sun/star/text/XTextDocument.hpp> +#include <com/sun/star/text/XText.hpp> +#include <com/sun/star/text/XTextTable.hpp> +#include <com/sun/star/text/XTextCursor.hpp> + +#include <comphelper/processfactory.hxx> + +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<XInterface> init() override; + void triggerDesktopTerminate() override; + + CPPUNIT_TEST_SUITE(SwXTextTable); + CPPUNIT_TEST(testAddEventListener); + CPPUNIT_TEST(testRemoveEventListener); + CPPUNIT_TEST_SUITE_END(); + +private: + css::uno::Reference<css::lang::XComponent> 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<XInterface> SwXTextTable::init() +{ + component_ = loadFromDesktop("private:factory/swriter", "com.sun.star.text.TextDocument"); + 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"), + UNO_QUERY_THROW); + xTable->initialize(4, 3); + xText->insertTextContent(xCursor, xTable, false); + CPPUNIT_ASSERT(xCursor.is()); + return Reference<XInterface>(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..9a0e26d4d --- /dev/null +++ b/sw/qa/api/terminate.cxx @@ -0,0 +1,75 @@ +/* -*- 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 <sal/config.h> + +#include <cppunit/TestAssert.h> +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/plugin/TestPlugIn.h> + +#include <com/sun/star/frame/Desktop.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/text/XText.hpp> +#include <com/sun/star/text/XTextCursor.hpp> +#include <com/sun/star/text/XTextDocument.hpp> +#include <com/sun/star/text/XTextTable.hpp> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/XInterface.hpp> +#include <comphelper/processfactory.hxx> +#include <test/bootstrapfixture.hxx> +#include <test/lang/xcomponent.hxx> +#include <unotest/macros_test.hxx> + +class TerminateTest final : public test::BootstrapFixture, + public unotest::MacrosTest, + public apitest::XComponent +{ +public: + void setUp() override; + + css::uno::Reference<css::uno::XInterface> 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<css::uno::XInterface> TerminateTest::init() +{ + auto const component + = loadFromDesktop("private:factory/swriter", "com.sun.star.text.TextDocument"); + css::uno::Reference<css::text::XTextDocument> xTextDocument(component, + css::uno::UNO_QUERY_THROW); + css::uno::Reference<css::lang::XMultiServiceFactory> xMSF(component, css::uno::UNO_QUERY_THROW); + css::uno::Reference<css::text::XText> xText = xTextDocument->getText(); + css::uno::Reference<css::text::XTextCursor> xCursor = xText->createTextCursor(); + css::uno::Reference<css::text::XTextTable> 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<css::uno::XInterface>(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: */ |